package com.itheima.exception;

import java.util.Arrays;

public class Demo02 {
    public static void main(String[] args) {
        int[] arr=null;
        try {
            sing(arr);
        } catch (NullPointerException e) {
            System.out.println("大哥,逮住了一个空指针");
        }

        while (true){}
    }


    public static void sing(int[] arr) throws NullPointerException{
        try {
            if(arr==null){
               // System.out.println("数组为空");
               // return;
                //现成给你制造一个异常对象
                throw new NullPointerException();
               // System.out.println("嘿嘿嘿,我最帅");
            }
        } catch (NullPointerException e) {
            System.out.println("大哥,发现一个空指针");
        }

            for (int i = 0; i < arr.length; i++) {
                System.out.println(arr[i]);
            }

    }
}
